<!-- 换签审核 -->
<template>
  <div v-if="getData">
    <el-header v-if="workItemId" height="36px">
      <header-title :title="headerTitle" />
    </el-header>
    <!-- 项目基础信息 -->
    <ProjectBasicInfo :prj-id="prjDetail.prjId" :prj-type="prjDetail.prjType"/>
    <!-- 站址信息 -->
    <ProjectSiteInfo :prj-id="prjDetail.prjId" />
    <MaterialInfo :prjDetail="prjDetail"></MaterialInfo>
    <LabelInfo :prjDetail="prjDetail" :isEdit="isEdit"></LabelInfo>
    <LabelPhotoInfo :prjDetail="prjDetail" v-if="showLabelPhoto"></LabelPhotoInfo>
    <!-- 项目审批信息 -->
    <ProjectApprovalInfo :process-inst-id="Number(workDetail.processInstID)" />
    <!-- 按钮提交流程 -->
    <ButtonProcess
      v-if="isShowType"
      ref="btnProcess"
      :isEdit="isEdit"
      :prjDetail="prjDetail"
      :workFlowData="workDetail"
    />
  </div>
</template>

<script>
import HeaderTitle from '@/components/basic/HeaderTitle'
import ProjectBasicInfo from '@/components/jn/JnPrjDetail.vue'
import ProjectSiteInfo from '@/components/jn/JnSiteDetail'
import ProjectApprovalInfo from '@/components/jn/JnTaskDetail'
import ButtonProcess from './components/ButtonProcess.vue'
import MaterialInfo from "@/views/material/changeLabel/components/materialInfo.vue";
import LabelInfo from "@/views/material/changeLabel/components/labelInfo.vue";
import LabelPhotoInfo from "@/views/material/changeLabel/components/LabelPhotoInfo.vue";
import { getWFWorkItemApi } from '@/api/acceptanceManagement/acceptanceMange'
import { getQueryObject } from '@/utils'
import {isVirtualOrRoom, querySwapLabelInfo} from "@/api/material";
import {getBackActivities} from "@/api/workFlow";
export default {
  name: 'ChangeLabel',
  components: {
    MaterialInfo,
    LabelInfo,
    LabelPhotoInfo,
    ButtonProcess,
    ProjectBasicInfo,
    ProjectSiteInfo,
    ProjectApprovalInfo,
    HeaderTitle
  },
  data() {
    return {
      // 顶部标题名字
      headerTitle: '',
      // 是否显示下一步 退回 按钮
      isShowType: true,
      getData:false,
      type:'',
      workItemId:'',
      workDetail:{},
      prjDetail:{},
      isEdit:false,
      showLabelPhoto:false,
    }
  },
  created() {
    const { workItemId, type } = getQueryObject()
    this.type = type;
    this.workItemId = workItemId;
    // 已办done 代办todo 存在workItemId
    if (this.type === 'done') {
      this.isShowType = false
    }
    this.getWFWorkItem()
  },
  methods: {
    // 页面初始化获取processInid 流程节点 以及浏览器地址数据
    async getWFWorkItem() {
        getWFWorkItemApi(this.workItemId).then((res)=>{
        if(+res.code === 200){
          this.workDetail = res.data
          this.getProjectInfo(res.data.bizObject?.bizSeq,res.data.bizObject?.prjId);
          if (this.type === 'todo') {
              this.getIsEdit();
          }
        }
      })
    },
    getIsEdit(){
        getBackActivities({
            processInstId: this.workDetail.processInstID,
            actInsetId: this.workDetail.activityInstID,
            route: '',
            excludeActDefIds: ''
        }).then(res => {
            if(res.data?.length>0){
                this.isEdit = false
            }else{
                this.isEdit = true
            }
        })
    },
    async getProjectInfo(bizSeq,prjId){
        querySwapLabelInfo(bizSeq).then((res)=>{
            if(+res.code === 200){
              this.prjDetail = res.data
              this.headerTitle=`${res.data.prjName}-换签-${this.workDetail.activityInstName}`
              this.getData=true
              this.getShowLabelPhoto(prjId,res.data.viewType,res.data.specState)
            }
        })
    },
    // 阻断修复
    getShowLabelPhotoFix(viewType,specState) {
      if (+viewType === 1) {
        if (+specState !== 1) {
          this.showLabelPhoto = true;
        }
      } else {
        this.showLabelPhoto = true;
      }
    },
    getShowLabelPhoto(prjId,viewType,specState){
        isVirtualOrRoom(prjId).then((res)=>{
            if(+res.code !== 200){
                return Promise.reject(res)
            }else{
                if(res.data && +viewType !== 2){
                    this.getShowLabelPhotoFix(viewType,specState)
                }
            }
        })
    }
  }
}
</script>
<style lang="scss" scoped></style>
